@extends('layout.home')
	@section('title','购物车')
    @section('detail')
        <h4 style="color: #52d0c4;">我的购物车</h4>
    @endsection
@section('content')
	<style type="text/css">

		td,th{
		    text-align:center;
		    color:#333;
		   }
		   th{
		   	font-size:16px;
		   }

	</style>
<div class="container">
	<div class="check-out">
		<h3 style="color:orangered">  
			我的宝贝
   		</h3>  
    	    <table>
			    <tbody>
				    <tr style="background:coral;color:#666">
						<th class="pull-left"><input name="allSelected" type="checkbox">&nbsp;全选</th>
						<th>商品</th>
						<th>数量</th>
						<th>商品尺寸</th>
						<th>商品颜色</th>
						<th>商品价格</th>
						<th>操作</th>
				    </tr>
					<form action="/home/order/add" method="post">
					@if(!empty($carts))
				    @foreach($carts as $k=>$v) 


				    <tr class="info" style="border-bottom:solid 1px coral">
						<td class="pull-left check">
							<input type="checkbox" name="data[{{$v['id']}}][goods_id]" value="{{$v['id']}}">
						</td>
						
						<td class="ring-in"><a href="/home/detail/{{$v['id']}}.html" class="at-in"><img src="{{$v['img']->path}}" class="img-responsive" alt=""></a>
							<div class="sed">
								<p>{!!$v['info']->title!!}</p>
							</div>
							<div class="clearfix"></div>
						</td>
						<td class="">
							<input style="width:40px;text-align:center" type="text" name="data[{{$v['id']}}][num]" value="{{$v['number']}}"></td>		
						<td>{{$v['size']}}</td>
						<td>{{$v['color']}}</td>
						<td>￥{{$v['info']->price * $v['number']}}</td>
						<td>
         					<span class="glyphicon glyphicon-trash"></span>
        				</td>
				  	</tr>
				  	<input type="hidden" name="data[{{$v['id']}}][color]" value="{{$v['color']}}" >
				  	<input type="hidden" name="data[{{$v['id']}}][size]" value="{{$v['size']}}">
				 	@endforeach
				 	@endif
				</tbody>	
			</table>
		{{csrf_field()}}
		<!-- <input type="hidden" name="order_id" value="" > -->
		<button  class="btn btn-1 btn-warning">确认支付</button>
	</form>
	<div class="clearfix"> </div>
    </div>
    
     <script type="text/javascript">
		    var allBox = $('input[type=checkbox]');
		 	$('input[type=checkbox]').eq(0).click(function(){
		 		if($(this).is(':checked') == true){
		 			// alert('1');
		 			allBox.prop('checked',true);
		 		}else{
		 			// alert(0);
		 			allBox.prop('checked',false);
		 		}
		 	});

		 	$('button').click(function(){
		 		$('.check input').each(function(){

		 			if($(this).is(':checked') == false){
		 				// alert($(this).val());
		 				$(this).parents('tr').find('input').attr('name','');
		 				$(this).parents('tr').next().attr('name','');
		 				$(this).parents('tr').next().next().attr('name','');
		 			}
		 		})
		 		
		 	});
		 	$('.glyphicon').mouseover(function(){
		 		$(this).css("cursor","pointer");
		 	});

		 	$('.glyphicon').click(function(){
		 		// alert($(this).parents('tr').index());
		 		//获取当前行 goods_id
		 		var id = $(this).parents('tr').find('input').eq(0).val();
		 		//发送ajax 删除session中的数组 键值为 goods_id
		 		$.get('/cart/delete',{'id':id},function(data){
		 			if((data) == 1){
		 				$('.glyphicon').parents('tr').css('display','none');
		 				alert('删除成功');
		 			}
		 		});
		 	});	
		  </script>
</div>
@endsection